package com.zsix.system.strategy.doEvent;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Component
public class DoEventContext {
    /**
     * 执行事件策略对象
     */
    private final List<DoEventStrategy> doEventStrategies;
    /**
     * 构造函数
     * @param doEventStrategies
     */
    public DoEventContext(List<DoEventStrategy> doEventStrategies){
        this.doEventStrategies=doEventStrategies;
    }
    /**
     * server容器
     */
    private Map<Integer, DoEventStrategy> doEventStrategyMap = new HashMap<>();

    /**
     * 初始化
     */
    @PostConstruct
    public void init(){
        doEventStrategyMap=doEventStrategies.stream()
                .collect(Collectors.toMap(DoEventStrategy::getType, o -> o));
    }
    /**
     * 获取方法
     * @param serviceType
     * @return
     */
    public DoEventStrategy getService(Integer serviceType){
        return doEventStrategyMap.get(serviceType);
    }
}
